package com.hzdesk.media.koreabatchmatvector.logic.view;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.config.AppConfig;
import com.hzdesk.media.koreabatchmatvector.logic.contract.MeetingNameContract;
import com.hzdesk.media.koreabatchmatvector.logic.persenter.MeetingNamePersenter;
import com.hzdesk.media.koreabatchmatvector.utils.SharedPreferencesUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MeetingNameActivity extends BaseActivity implements MeetingNameContract.IMeetingNameView{

    @BindView(R.id.activity_meeting_name_et)
    EditText activityMeetingNameEt;
    @BindView(R.id.activity_meeting_name_button_cancle)
    Button activityMeetingNameButtonCancle;
    @BindView(R.id.activity_meeting_name_button_ok)
    Button activityMeetingNameButtonOk;
    @BindView(R.id.activity_meeting_name_rl_bg)
    RelativeLayout activityMeetingNameRlBg;


    private MeetingNamePersenter meetingNamePersenter=new MeetingNamePersenter(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_meeting_name);
        ButterKnife.bind(this);
        meetingNamePersenter.initView(this);
        meetingNamePersenter.setOnHoverListenerAndOnFocusChangeListener(activityMeetingNameButtonCancle);
        meetingNamePersenter.setOnHoverListenerAndOnFocusChangeListener(activityMeetingNameButtonOk);
    }

    @OnClick({R.id.activity_meeting_name_button_cancle, R.id.activity_meeting_name_button_ok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_meeting_name_button_cancle:
                meetingNamePersenter.onClickCancle();
                break;
            case R.id.activity_meeting_name_button_ok:
                meetingNamePersenter.onClickOk();
                break;
        }
    }

    @Override
    public void setEditTextName(String name) {
        activityMeetingNameEt.setText(name);
        activityMeetingNameEt.setSelection(name.length());

    }

    @Override
    public void cancle() {
        finish();

    }

    @Override
    public void confim() {
        String name=activityMeetingNameEt.getText().toString();
        SharedPreferencesUtils sharedPreferencesUtils=SharedPreferencesUtils.getInstance(this);
        sharedPreferencesUtils.putDate(AppConfig.MEETING_NAME,name);
        finish();

    }
}
